<!--#include virtual="/app/common/jsLoader.asp" -->
<%
    require('/app/edk/edk.js');
    require('/app/edk/sql.js');
    require('/app/common/common.js');
    require('/deepcms/classic/public/server.js');
%>
<html>
	<head>
		<%=$$.cfg.headTags(null, true)%>
		<style type="text/css">
			body{
				background-color:white;
				padding:20px;
			}
			td{
				padding:3px;
			}
			
		</style>
		<link rel="stylesheet" href="/deepcms/classic/public/style.css" type="text/css"/>
	</head>
	<body>
		<script>
			Ext.onReady(function(){
				alert(99);
				//Ext.get('editForm').on('submit', function(){l(9)});				
			});
		</script>
<%
    var 
         isUpdate = !!Request('ID')()
        ,entity   = isUpdate
                    ? $$.sql('SELECT * FROM news WHERE ID={0}'.format(Request('ID')())).rsObj
                    : new Function('return "";');
%>   
        <h1 style="margin:10px;"><%=isUpdate?'更新':'创建'%>新闻<br /></h1>    
		<form id="editForm" method="post" class="edkForm" action ="/app/news/<%=isUpdate?'update':'create'%>/default.asp">
            <table width="100%">
                <tr>
                    <td width="10%"><label for="title">标题 Title：</label></td>
                    <td><input type="text" id="title" class="edk-input-2" style="width:98%;" name="title" value="<%=entity('title')%>" /></td>
                </tr>
                <tr>
                    <td>正文内容 Content：</td><td>
                    <textarea class="edk-htmlEditor" name="content"><%=entity('content')%></textarea></td>
                </tr>
                <tr>
                    <td>上传附件 Attachment(s)：</td>
                    <td>
                        <iframe src="/app/upload/classic.htm" FRAMEBORDER="0" SCROLLING="NO" width="100%" height="40"></iframe>
                    </td>
                </tr>
                <tr>
                    <td>新闻类别  Class:</td>
                    <td>
                    	<%
                    	
/*
 * These classes are derivatives of the similarly named classes in the ExtJS Library.
 * The original license:
 * Ext 2.02 is licensed under the terms of the Open Source LGPL 3.0 license. 
 * Copyright (c) 2008, ExtJS, LLC. All rights reserved.
 * This Library wants to use Ext in an open source project that precludes using nson-open source software
 * http://www.gnu.org/licenses/lgpl.html
 */
$$.Template = function(html){
    var a = arguments;
    if(html.join){
        html = html.join("");
    }else if(a.length > 1){
        var buf = [];
        for(var i = 0, len = a.length; i < len; i++){
            if(typeof a[i] == 'object'){
                Object.apply(this, a[i]);
            }else{
                buf[buf.length] = a[i];
            }
        }
        html = buf.join('');
    }
    /**@private*/
    this.html = html;

   /**
    * 匹配模板变量的正则表达式
    * @type RegExp
    * @property
    */
    this.re = /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g
    // private
    this.codeRe = /\{\[((?:\\\]|.|\n)*?)\]\}/g    // private function used to call members
    this.call = function(fnName, value, allValues){
        return this[fnName](value, allValues);
    }
    // private
    this.applySubTemplate = function(id, values, parent, xindex, xcount){
        var t = this.tpls[id];
        if(t.test && !t.test.call(this, values, parent, xindex, xcount)){
            return '';
        }

        if(t.exec && t.exec.call(this, values, parent, xindex, xcount)){
            return '';
        }
        var vs = t.target ? t.target.call(this, values, parent) : values;
        parent = t.target ? values : parent;
        if(t.target && vs.pop){
            var buf = [];
            for(var i = 0, len = vs.length; i < len; i++){
                buf[buf.length] = t.compiled.call(this, vs[i], parent, i+1, len);
            }
            return buf.join('');
        }
        return t.compiled.call(this, vs, parent, xindex, xcount);
    },

    // private
    this.compileTpl = function(tpl){
        var useF = this.disableFormats !== true;
        var sep = ",";
        var fn = function(m, name, format, args, math){
            if(name.substr(0, 4) == 'xtpl'){
                return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'";
            }
            var v;
            if(name === '.'){
                v = 'values';
            }else if(name === '#'){
                v = 'xindex';
            }else if(name.indexOf('.') != -1){
                v = name;
            }else{
                v = "values['" + name + "']";
            }
            if(math){
                v = '(' + v + math + ')';
            }
            if(format && useF){
                args = args ? ',' + args : "";
                if(format.substr(0, 5) != "this."){
                    format = "fm." + format + '(';
                }else{
                    format = 'this.call("'+ format.substr(5) + '", ';
                    args = ", values";
                }
            }else{
                args= ''; format = "("+v+" === undefined ? '' : ";
            }
            return "'"+ sep + format + v + args + ")"+sep+"'";
        };
        var codeFn = function(m, code){
            return "'"+ sep +'('+code+')'+sep+"'";
        };

        var body;
        // branched to use + in gecko and [].join() in others
        body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"];
        body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn));
        body.push("'].join('');};");
        body = body.join('');
        eval(body);
        return this;
    },
    this.compile = this.compileTpl;
    /**
     * Returns an HTML fragment of this template with the specified values applied.
     * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
     * @return {String} The HTML fragment
     */
    this.applyTemplate = function(values){
        return this.master.compiled.call(this, values, {}, 1, 1);
    }
    // @private
	this.Ex_constructor = function(){
	    var s = this.html;
	
	    s = ['<tpl>', s, '</tpl>'].join('');
	
	    var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;
	
	    var nameRe = /^<tpl\b[^>]*?for="(.*?)"/;
	    var ifRe = /^<tpl\b[^>]*?if="(.*?)"/;
	    var execRe = /^<tpl\b[^>]*?exec="(.*?)"/;
	    var m, id = 0;
	    var tpls = [];
	
	    while(m = s.match(re)){
	       var m2 = m[0].match(nameRe);
	       var m3 = m[0].match(ifRe);
	       var m4 = m[0].match(execRe);
	       var exp = null, fn = null, exec = null;
	       var name = m2 && m2[1] ? m2[1] : '';
	       if(m3){
	           exp = m3 && m3[1] ? m3[1] : null;
	           if(exp){
	               fn = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ return '+($$.Template.htmlDecode(exp))+'; }');
	           }
	       }
	       if(m4){
	           exp = m4 && m4[1] ? m4[1] : null;
	           if(exp){
	               exec = new Function('values', 'parent', 'xindex', 'xcount', 'with(values){ '+($$.Template.htmlDecode(exp))+'; }');
	           }
	       }
	       if(name){
	           switch(name){
	               case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
	               case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
	               default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
	           }
	       }
	       tpls.push({
	            id: id,
	            target: name,
	            exec: exec,
	            test: fn,
	            body: m[1]||''
	        });
	       s = s.replace(m[0], '{xtpl'+ id + '}');
	       ++id;
	    }
	    for(var i = tpls.length-1; i >= 0; --i){
	        this.compileTpl(tpls[i]);
	    }
	    this.master = tpls[tpls.length-1];
	    this.tpls = tpls;
	}

    this.Ex_constructor();

    /**
     * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
     * @param {String} value The string to truncate
     * @param {Number} length The maximum length to allow before truncating
     * @param {Boolean} word True to try to find a common work break
     * @return {String} The converted text
     */
    this.ellipsis = $$.Template.ellipsis;
    this.ChineseDate = function(a){
    	return $$.lang.date.format(new Date(a), "YYYY");
    }
    //$$.Date.dateFormat.delegate(null, "ChineseDate");
};
/**
 * 为能在HTML显示的字符转义&、<、>以及'。
 * @return {String} 编码后的文本
 */
$$.Template.htmlEncode = function(isAndOff){
    var str = this.replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
    return isAndOff
    		? str.replace(/&/g, "&amp;")
    		: str;
}

/**
 * 将&、<、>以及'字符从HTML显示的格式还原。
 * @return {String} 编码后的文本
 * @credit Ext
 */
$$.Template.htmlDecode = function(v){
    return v.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');
}

	                    	//var sql = $$.newInstance($$.sql);
	                    	var rs = $$.sql('SELECT * FROM newsclass').rsObj;
	                    	rs.moveFirst();
	                    	var arr = [];
	                    	do{
	                    		arr.push({
	                    			ID : rs('ID').value
	                    			,title:rs('title').value
	                    		});
	                    		rs.moveNext();
	                    	}while(!rs.EOF);
                    		var tpl = new $$.Template($$.cfg.Tags('//tags/select'));
                    		Response.write(tpl.applyTemplate({
                    			 data : arr
                    			,thisID:entity('ClassID')
                    		}));
                    		
	                    	rs.close();
                    	%>
                    	 <a href="../../class">编辑分类</a>
                    </td>
                </tr>
                <tr>
                    <td>URL：</td>
                    <td>
                        <input type="text" class="edk-input-2" style="width:98%;" name="url" value="<%=entity('url')%>"  />
                    </td>
                </tr>
                <tr>
                    <td>发布日期：</td>
                    <td>
                        <input type="text" class="edk-input-2" style="width:98%;" name="createDate" value="<%=entity('createDate')%>"  />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <br />
                        <input type="submit" value="      保存 Save      " /> <input type="reset" value="      复位 Reset       " />
                    </td>
                </tr>
            </table>
            <%
            if(isUpdate){
            %>
                <input type="hidden" value="<%=Request('ID')()%>" name="ID" />
            <%
            }
            %>
		</form>
		
		<script>
            Ext.QuickTips.init();
            new Ext.form.HtmlEditor({
                 applyTo  : Ext.select('textarea.edk-htmlEditor').item(0)
                ,width    : "98%"
                ,height   : 500
            });
			Ext.get('editForm').on('submit', function(e){
				debugger
				var miss = Ext.fly('title').getValue() == ''
						|| Ext.fly('url').getValue() == ''
						|| Ext.fly('createDate').getValue() == '';
				
				if(miss){
					alert('请输入内容');					
					e.stopEvent();
					return false;
				}
			});
		</script>
	</body>
</html>
<%
	if(entity.close){
    	entity.close();
	}
	if(entity.activeConnection){
	    entity.activeConnection.close();
	}
%>
